package com.atmilan.quartz.sync.pull.daigo.service.impl;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import com.alibaba.fastjson.JSONObject;
import com.atmilan.quartz.constant.enums.SyncStatusEnum;
import com.atmilan.quartz.model.entity.buyer.Supplier;
import com.atmilan.quartz.model.entity.crmeb.StoreProductAttrValue;
import com.atmilan.quartz.model.entity.crmeb.SystemConfig;
import com.atmilan.quartz.utils.product.DaigoProductUtil;
import com.xxl.job.core.context.XxlJobHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.atmilan.quartz.constant.Constants;
import com.atmilan.quartz.constant.enums.ProductTypeEnum;
import com.atmilan.quartz.model.dto.daigo.DaigoProductResDTO;
import com.atmilan.quartz.model.dto.crmeb.StoreProductCrmebRequest;
import com.atmilan.quartz.model.entity.daigo.DaigoProduct;
import com.atmilan.quartz.model.entity.daigo.DaigoProductSku;
import com.atmilan.quartz.model.entity.daigo.DaigoProductSkuMerged;
import com.atmilan.quartz.model.entity.crmeb.StoreProduct;
import com.atmilan.quartz.service.IStoreProductAttrService;
import com.atmilan.quartz.service.IStoreProductAttrValueService;
import com.atmilan.quartz.service.IStoreProductNormService;
import com.atmilan.quartz.service.IStoreProductService;
import com.atmilan.quartz.service.ISystemConfigService;
import com.atmilan.quartz.sync.pull.daigo.converter.BaseDaigoProductConverter;
import com.atmilan.quartz.sync.pull.daigo.converter.BaseDaigoSkuConverter;
import com.atmilan.quartz.sync.pull.daigo.service.IDaigoBrandService;
import com.atmilan.quartz.sync.pull.daigo.service.IDaigoCateService;
import com.atmilan.quartz.sync.pull.daigo.service.IDaigoProductService;
import com.atmilan.quartz.sync.pull.daigo.service.IDaigoProductSkuMergedService;
import com.atmilan.quartz.sync.pull.daigo.service.IDaigoProductSkuService;
import com.atmilan.quartz.sync.pull.daigo.service.IDaigoSyncService;
import com.atmilan.quartz.utils.OSSUtil;
import com.atmilan.quartz.utils.RedisUtil;
import com.atmilan.quartz.utils.source.SourceDaigoProductUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;

/**
 * @author hupeng
 */
@Slf4j
@Service
public class DaigoSyncServiceImpl implements IDaigoSyncService {
    @Autowired
    OSSUtil ossUtil;
    @Autowired
    private IDaigoProductService daigoProductService;
    @Resource
    private BaseDaigoProductConverter baseDaigoProductConverter;
    @Autowired
    private IDaigoProductSkuMergedService daigoProductSkuMergedService;
    @Resource
    private BaseDaigoSkuConverter baseDaigoSkuConverter;
    @Autowired
    private IDaigoProductSkuService daigoProductSkuService;
    @Autowired
    IDaigoBrandService daigoBrandService;
    @Autowired
    IDaigoCateService daigoCateService;
    @Autowired
    RedisUtil redisUtil;
    @Autowired
    IStoreProductService storeProductService;
    @Autowired
    IStoreProductNormService storeProductNormService;
    @Autowired
    IStoreProductAttrService storeProductAttrService;
    @Autowired
    IStoreProductAttrValueService storeProductAttrValueService;
    @Autowired
    private ISystemConfigService systemConfigService;
    @Autowired
    SourceDaigoProductUtil sourceDaigoProductUtil;
    @Autowired
    DaigoProductUtil daigoProductUtil;

    /**
     * 获取远程daigo数据并保存到数据源
     */
    @Override
    public Boolean syncDaigoProduct() {
        // 数据清空
        daigoProductService.deleteAll();
        daigoProductSkuService.deleteAll();
        daigoProductSkuMergedService.deleteAll();

        int pageNo = 1;
        int pageSize = 100;
        int pageCount = 1;

        long millis = System.currentTimeMillis();
        // 循环获取daigo商品数据并保存
        while (pageNo <= pageCount) {
            try {
                DaigoProductResDTO resDTO = daigoProductUtil.selectDaigoPage(pageNo, pageSize);
                if (null != resDTO && CollectionUtils.isEmpty(resDTO.getProduct())) {
                    log.info("resDTO=>:" + JSONObject.toJSONString(resDTO).toString());
                    XxlJobHelper.log("resDTO=>:" + JSONObject.toJSONString(resDTO).toString());
                }
                // 到达末页
                if (null == resDTO || CollectionUtils.isEmpty(resDTO.getProduct())) {
                    pageNo++;
                    continue;
                }
                pageCount = resDTO.getPager().getMaxPage();
                // 处理数据保存
                processDaigoProduct(resDTO.getProduct());
                log.info("--------------- daigo远程抓取数据, 第: {} 页, 总共: {} 页, 总耗时: {} 分  ---------------", pageNo, pageCount, (int) ((System.currentTimeMillis() - millis) / 1000 / 60));
            } catch (Exception e) {
                e.printStackTrace();
            }

            pageNo++;
        }
        return true;
    }

    /**
     * 下发daigo商品
     */
    @Override
    public Boolean pushDaigoProduct() {

        try {
            // 当次更新少于5000条, 则不更新, 并且重新拉取
            int count = daigoProductService.count();
            if (5000 > count) {
                systemConfigService.update(Wrappers.<SystemConfig>lambdaUpdate()
                        .eq(SystemConfig::getName, Constants.DAIGO_SYNC_STATUS)
                        .set(SystemConfig::getFormId, SyncStatusEnum.PUSH)
                        .set(SystemConfig::getUpdateTime, new Date()));
                log.info("--------------- daigo商品源数据, 少于规定条数, 不进行下发, 总条数为: {} ---------------", count);
                return false;
            }

            // 将所有daigo商品更新状态置为未更新
            storeProductService.update(Wrappers.<StoreProduct>lambdaUpdate()
                    .eq(StoreProduct::getIsEurope, ProductTypeEnum.DAIGO.getCode())
                    .set(StoreProduct::getUpdateFlag, false)
            );

            // 商品更新操作
            int pageNo = 1;
            int pageSize = 100;
            int maxPage = (count + pageSize - 1) / pageSize;
            log.info("--------------- 开始分页查询daigo商品源数据, 本次更新总条数为: {} ---------------", count);

            long millis = System.currentTimeMillis();
            while (pageNo <= maxPage) {

                PageHelper.startPage(pageNo, pageSize);
                List<DaigoProduct> daigoProducts = daigoProductService.list();
                PageInfo<DaigoProduct> pageInfo = PageInfo.of(daigoProducts);
                List<DaigoProduct> products = pageInfo.getList();
                pushDaigoProduct(products);

                log.info("--------------- daigo下发商品到数据库, 本次实际获取数量:{},当前页数: {}, 总页数: {}, 耗时: {} 分 ---------------", daigoProducts.size(), pageNo, maxPage, (int) ((System.currentTimeMillis() - millis) / 1000 / 60));
                pageNo++;
            }
            // 图搜删除
            storeProductService.delSeachImage(ProductTypeEnum.DAIGO);
            // 下架所有未更新数据
            storeProductService.update(Wrappers.<StoreProduct>lambdaUpdate()
                    .eq(StoreProduct::getIsEurope, ProductTypeEnum.DAIGO.getCode())
                    .eq(StoreProduct::getUpdateFlag, false)
                    .eq(StoreProduct::getIsShow, true)
                    .eq(StoreProduct::getIsDel, false)
                    .set(StoreProduct::getIsShow, false)
                    .set(StoreProduct::getStock, 0)
                    .set(StoreProduct::getLastPushTime, new Date())
                    .set(StoreProduct::getIsTusou, false)
            );
            // 下架所有sku库存
            storeProductService.downloadSku(ProductTypeEnum.DAIGO.getCode());

        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

        return true;
    }

    private void updateSku(List<DaigoProductSku> skuList) {
        skuList.forEach(sku -> {
            sku.setEditTime(new Date());
            sku.setCreateTime(new Date());
        });
        daigoProductSkuService.saveBatch(skuList);
    }

    public void updateSkuMerged(List<DaigoProductSku> skuList) {
        Map<String, Integer> sumStockMap = skuList.stream().collect(Collectors.groupingBy(c -> c.getAttrKey(), Collectors.summingInt(DaigoProductSku::getStock)));
        skuList = skuList.stream().filter(sku -> StringUtils.isNotBlank(sku.getAttrKey() + sku.getSize())).map(sku -> sku.setStock(sumStockMap.get(sku.getAttrKey()))).collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(DaigoProductSku::getAttrKey))), ArrayList::new));
        List<DaigoProductSkuMerged> skuMergeds = new ArrayList<>();
        skuList.forEach(sku -> {
            DaigoProductSkuMerged skuMerged = baseDaigoSkuConverter.toMergedModel(sku);
            skuMerged.setEditTime(DateUtil.date());
            skuMerged.setCreateTime(DateUtil.date());
            skuMergeds.add(skuMerged);
        });

        daigoProductSkuMergedService.saveBatch(skuMergeds);
    }

    /**
     * 数据处理
     *
     * @param @param voList
     * @return void
     * @throws
     * @Description:
     * @author daigb
     */
    private void processDaigoProduct(List<DaigoProductResDTO.Product> voList) {
        try {
            for (DaigoProductResDTO.Product vo : voList) {
                // 排除下架商品
                if (vo.getOnSale() == 0) {
                    continue;
                }

                String goodsId = vo.getGoodsId();
                String redisKey = "job:sync:daigo:" + goodsId;
                if (null != redisUtil.get(redisKey)) {
                    log.info("--------------- 该商品: {}, 已保存, 不进行处理  ---------------", goodsId);
                    continue;
                } else {
                    redisUtil.set(redisKey, goodsId, 3L, TimeUnit.MINUTES);
                }
                DaigoProduct daigoProduct = baseDaigoProductConverter.toModel(vo);
                // 售价大于0 并且有sku
                if (CollectionUtils.isNotEmpty(vo.getSkus()) && 0 < Integer.parseInt(vo.getSalePrice())) {
                    daigoProduct.setEditTime(DateUtil.date());
                    daigoProduct.setCreateTime(DateUtil.date());
                    daigoProductService.save(daigoProduct);
                    List<DaigoProductSku> list = baseDaigoSkuConverter.toModelList(vo.getSkus());
                    updateSku(list);
                    updateSkuMerged(list);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void pushDaigoProduct(List<DaigoProduct> daigoProduct) {
        try {
            for (DaigoProduct bp : daigoProduct) {
                List<DaigoProductSkuMerged> skuMergeds = daigoProductSkuMergedService.list(Wrappers.<DaigoProductSkuMerged>lambdaQuery()
                                .eq(DaigoProductSkuMerged::getGoodsId, bp.getGoodsId())
//                        .eq(DaigoProductSkuMerged::getQihuo, false)
//                        .notLike(DaigoProductSkuMerged::getColor, "期货")
//                        .notLike(DaigoProductSkuMerged::getColor, "预售")
//                        .notLike(DaigoProductSkuMerged::getSize, "期货")
//                        .notLike(DaigoProductSkuMerged::getSize, "预售")
                                .isNotNull(DaigoProductSkuMerged::getSize)
                                .gt(DaigoProductSkuMerged::getStock, 0)
                );
                log.info("获取skuMergeds,参数:goodsId:{},获取数量:{}", bp.getGoodsId(), skuMergeds.size());
                if (CollectionUtils.isEmpty(skuMergeds)) {
                    continue;
                }
//                if(bp.getGoodsName().contains("期货") || bp.getGoodsName().contains("预售") || bp.getGoodsCode().contains("期货") || bp.getGoodsCode().contains("预售")) {
//                    continue;
//                }
                // 库存计算
                int stock = 0;
                for (DaigoProductSkuMerged sku : skuMergeds) {
                    stock += sku.getStock();
                }

                // 对象创建
                DaigoProduct daigoProductCrmeb = new DaigoProduct();
                BeanUtils.copyProperties(bp, daigoProductCrmeb);

                // 构建实体
                StoreProductCrmebRequest storeProductCrmebRequest = sourceDaigoProductUtil.buildCrmebProduct(daigoProductCrmeb, skuMergeds);

                // 数据保存
                StoreProduct storeProduct = storeProductService.getByBarCode(storeProductCrmebRequest.getBarCode(), storeProductCrmebRequest.getSuppliersId(), storeProductCrmebRequest.getKeyword());
                boolean crmebUpdate = true;
                if (null != storeProduct && null != storeProduct.getLastPushTime()) {
                    long time = (System.currentTimeMillis() - storeProduct.getLastPushTime().getTime()) / 1000 / 60;
                    if (60 > time) {
                        log.info("--------------- 该商品: {} 上次crmeb更新时间: {} 小于一小时, 不进行更新 ---------------", storeProductCrmebRequest.getBarCode(), storeProduct.getLastPushTime());
                        crmebUpdate = false;
                        storeProductService.update(Wrappers.<StoreProduct>lambdaUpdate()
                                .eq(StoreProduct::getId, storeProduct.getId())
                                .set(StoreProduct::getUpdateFlag, true)
                        );
                    }
                }
                if (crmebUpdate) {
                    storeProductService.saveOtProduct(storeProductCrmebRequest, storeProduct, stock);
                    //saveCrmebProduct(storeProductCrmebRequest, storeProduct, stock);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
    }

//    private void saveCrmebProduct(StoreProductCrmebRequest storeProductCrmebRequest, StoreProduct storeProduct, Integer stock) {
//        /****** 主表数据保存 *******/
//        StoreProduct storeProductUpdate = new StoreProduct();
//        BeanUtils.copyProperties(storeProductCrmebRequest, storeProductUpdate);
//        storeProductUpdate.setStock(stock);
//        storeProductUpdate.setUpdateFlag(true);
//        boolean isUpdate = null != storeProduct;
//        Integer productId = 0;
//        String barCode = storeProductCrmebRequest.getBarCode();
//        if (isUpdate) {
//            storeProductService.update(Wrappers.<StoreProduct>lambdaUpdate()
//                    .eq(StoreProduct::getId, storeProduct.getId())
//                    .set(StoreProduct::getPrice, storeProductUpdate.getPrice())
//                    .set(null != storeProductUpdate.getPromotePrice(), StoreProduct::getPromotePrice, storeProductUpdate.getPromotePrice())
//                    .set(null != storeProductUpdate.getVipPrice(), StoreProduct::getVipPrice, storeProductUpdate.getVipPrice())
////                    .set(null != storeProductUpdate.getKeyword(), StoreProduct::getKeyword, storeProductUpdate.getKeyword())
//                    .set(null != storeProductUpdate.getOtPrice(), StoreProduct::getOtPrice, storeProductUpdate.getOtPrice())
//                    .set(null != storeProductUpdate.getPostage(), StoreProduct::getPostage, storeProductUpdate.getPostage())
//                    .set(null != storeProductUpdate.getBrandId(), StoreProduct::getBrandId, storeProductUpdate.getBrandId())
//                    .set(null != storeProductUpdate.getBrandName(), StoreProduct::getBrandName, storeProductUpdate.getBrandName())
////                    .set(null != storeProductUpdate.getSuppliersId(), StoreProduct::getSuppliersId, storeProductUpdate.getSuppliersId())
////                    .set(null != storeProductUpdate.getSuppliersName(), StoreProduct::getSuppliersName, storeProductUpdate.getSuppliersName())
//                    .set(null != storeProductUpdate.getCateId(), StoreProduct::getCateId, storeProductUpdate.getCateId())
//                    .set(null != storeProductUpdate.getIsPromoter(), StoreProduct::getIsPromoter, storeProductUpdate.getIsPromoter())
//                    .set(null != storeProductUpdate.getGiveIntegral(), StoreProduct::getGiveIntegral, storeProductUpdate.getGiveIntegral())
//                    .set(null != storeProductUpdate.getCost(), StoreProduct::getCost, storeProductUpdate.getCost())
//                    .set(null != storeProductUpdate.getSourceCost(), StoreProduct::getSourceCost, storeProductUpdate.getSourceCost())
//                    .set(null != storeProductUpdate.getSpecType(), StoreProduct::getSpecType, storeProductUpdate.getSpecType())
//                    .set(null != storeProductUpdate.getErpPromFlag(), StoreProduct::getErpPromFlag, storeProductUpdate.getErpPromFlag())
//                    .set(null != storeProductUpdate.getPromoteFlag(), StoreProduct::getPromoteFlag, storeProductUpdate.getPromoteFlag())
////                    .set(null != storeProductUpdate.getAddTime(), StoreProduct::getAddTime, storeProductUpdate.getAddTime())
//                    .set(null != storeProductUpdate.getLastPushTime(), StoreProduct::getLastPushTime, storeProductUpdate.getLastPushTime())
////                    .set(null != storeProductUpdate.getIsEurope(), StoreProduct::getIsEurope, storeProductUpdate.getIsEurope())
//                    .set(null != storeProductUpdate.getTempId(), StoreProduct::getTempId, storeProductUpdate.getTempId())
//                    .set(StoreProduct::getUpdateFlag, storeProductUpdate.getUpdateFlag())
//                    .set(StoreProduct::getIsShow, true)
//                    .set(StoreProduct::getStock, stock)
////                    .set(StoreProduct::getTmall, storeProductUpdate.getTmall())
//                    );
//            productId = storeProduct.getId();
//            barCode = storeProduct.getBarCode();
//        } else {
//            // 查询标准商品
//            StoreProductNorm normProduct = storeProductNormService.getOne(Wrappers.<StoreProductNorm>lambdaQuery()
//                    .eq(StoreProductNorm :: getKeyword, storeProductUpdate.getKeyword())
//                    .last("LIMIT 1")
//                    );
//            // 使用标准商品配置
//            if(null != normProduct) {
//                convertProduct(normProduct, storeProductUpdate);
//            }
//            
//            storeProductService.save(storeProductUpdate);
//            productId = storeProductUpdate.getId();
//        }
//        /****** attr表保存 ********/
//        if (isUpdate) {
//            storeProductAttrService.removeByProductId(productId);
//        }
//        List<StoreProductAttr> attrs = storeProductCrmebRequest.getAttr();
//        for (StoreProductAttr attr : attrs) {
//            attr.setProductId(productId);
//            attr.setBarCode(barCode);
//            attr.setAttrValues(StringUtils.strip(attr.getAttrValues().replace("\"", ""), "[]"));
//        }
//        storeProductAttrService.saveBatch(attrs);
//        /****** value表保存 *********/
//        Map<String, StoreProductAttrValue> dbStoreProductAttrValueMap = new HashMap<>();
//        if (isUpdate) {
//            List<StoreProductAttrValue> dbStoreProductAttrValues = storeProductAttrValueService.list(Wrappers.<StoreProductAttrValue>lambdaQuery().eq(StoreProductAttrValue::getProductId, productId));
//            dbStoreProductAttrValueMap = dbStoreProductAttrValues.stream().collect(Collectors.toMap(StoreProductAttrValue::getSourceSkuId, s -> s, (value1, value2) -> {
//                return value1;
//            }));
//            // 删除所有value
//            storeProductAttrValueService.removeByProductId(productId);
//        }
//        List<StoreProductAttrValueRequest> storeProductAttrValuesRequest = storeProductCrmebRequest.getAttrValue();
//        List<StoreProductAttrValue> values = new ArrayList<>();
//        for (StoreProductAttrValueRequest attrValuesRequest : storeProductAttrValuesRequest) {
//            attrValuesRequest.setProductId(productId);
//            attrValuesRequest.setBarCode(barCode);
//            StoreProductAttrValue spav = new StoreProductAttrValue();
//            BeanUtils.copyProperties(attrValuesRequest, spav);
//            List<String> skuList = new ArrayList<>();
//            for (Map.Entry<String, String> vo : attrValuesRequest.getAttrValue().entrySet()) {
//                skuList.add(vo.getValue());
//                spav.setSuk(String.join(",", skuList));
//            }
//            spav.setAttrValue(JSON.toJSONString(attrValuesRequest.getAttrValue()));
//            StoreProductAttrValue tempValue = dbStoreProductAttrValueMap.get(spav.getSourceSkuId());
//            if (null != tempValue) {
//                spav.setId(tempValue.getId());
//            }
//            values.add(spav);
//        }
//        storeProductAttrValueService.saveOrUpdateBatch(values);
//        /****** result表保存 ******/
//        if (isUpdate) {
//            storeProductAttrResultService.remove(Wrappers.<StoreProductAttrResult>lambdaQuery().eq(StoreProductAttrResult::getProductId, productId));
//        }
//        StoreProductAttrResult attrResult = new StoreProductAttrResult(0, productId, systemAttachmentService.clearPrefix(JSON.toJSONString(storeProductCrmebRequest.getAttrValue())), Integer.parseInt(String.valueOf(System.currentTimeMillis() / 1000L)), Constants.PRODUCT_TYPE_NORMAL, barCode);
//        storeProductAttrResultService.save(attrResult);
//        /****** Description表保存 ******/
//        if (isUpdate) {
//            storeProductDescriptionService.deleteByProductId(productId);
//        }
//        StoreProductDescription spd = new StoreProductDescription(productId, storeProductCrmebRequest.getContent().length() > 0 ? systemAttachmentService.clearPrefix(storeProductCrmebRequest.getContent()) : storeProductCrmebRequest.getContent(), barCode);
//        storeProductDescriptionService.save(spd);
//    }

    /**
     *
     * @Description:
     * @author daigb
     * @param @param sourceProduct 标准商品数据
     * @param @param targetProduct 要替换的商品
     * @return void
     * @throws
     */
//    private void convertProduct(StoreProductNorm sourceProduct, StoreProduct targetProduct) {
//        if(StringUtil.isNotEmpty(sourceProduct.getStoreName())) {
//            targetProduct.setStoreName(sourceProduct.getStoreName());
//        }
//        if(StringUtil.isNotEmpty(sourceProduct.getStoreInfo())) {
//            targetProduct.setStoreInfo(sourceProduct.getStoreInfo());
//        }
//        if(StringUtil.isNotEmpty(sourceProduct.getComposition())) {
//            targetProduct.setComposition(sourceProduct.getComposition());
//        }
//        if(StringUtil.isNotEmpty(sourceProduct.getDimension())) {
//            targetProduct.setDimension(sourceProduct.getDimension());
//        }
//        if(StringUtil.isNotEmpty(sourceProduct.getSeason())) {
//            targetProduct.setSeason(sourceProduct.getSeason());
//        }
//        if(StringUtil.isNotEmpty(sourceProduct.getSeasonCode())) {
//            targetProduct.setSeasonCode(sourceProduct.getSeasonCode());
//        }
//        targetProduct.setNormId(sourceProduct.getId());
//    }

    /**
     * 下架商品并置空库存
     *
     * @author daigb
     * @date: 2022-05-11 15:52
     */
    private void shutdowmProduct(String barCode, Supplier supplier) {
        // 图搜删除
        storeProductService.delSeachImageByBarcode(barCode);
        // 商品下架
        storeProductService.update(Wrappers.<StoreProduct>lambdaUpdate()
                .eq(StoreProduct::getBarCode, barCode)
                .eq(StoreProduct::getIsEurope, supplier.getIsEurope())
                .eq(StoreProduct::getIsShow, true)
                .eq(StoreProduct::getIsDel, false)
                .set(StoreProduct::getIsShow, false)
                .set(StoreProduct::getStock, 0)
                .set(StoreProduct::getLastPushTime, new Date())
                .set(StoreProduct::getIsTusou, false)
        );
        storeProductAttrValueService.update(Wrappers.<StoreProductAttrValue>lambdaUpdate()
                .eq(StoreProductAttrValue::getBarCode, barCode)
                .set(StoreProductAttrValue::getStock, 0)
        );
    }

}
